import request from "@/utils/request";
// 切换路由页面无法实时切换，导致还是走之前的URL 1.路由守卫刷新  2.直接使用统一baseurl管理
import baseUrl from "@/utils/requestBase";

import { TimeToStrDate } from "@/utils/utils";

export default {
  getDictData(dictType) {
    return request({
      url: `/${dictType}`,
      method: "get",
      baseURL: `${baseUrl.dict}`,
    });
  },

  getDictList(searchModel) {
    console.log("这是搜索方法", searchModel);
    const params = searchModel;
    // 进行日期的处理
    if (searchModel.time) {
      console.log("进行日期处理");
      let beginTime = TimeToStrDate(searchModel.time[0]);
      let endTime = TimeToStrDate(searchModel.time[1]);
      delete params.time;
      params.beginTime = beginTime;
      params.endTime = endTime;
      console.log("结果", params);
    }
    return request({
      method: "get",
      baseURL: `${baseUrl.dict}`,
      params,
    });
  },

  getDictTypeData(id) {
    return request({
      url: `/lazyGetOne/${id}`,
      method: "get",
      baseURL: `${baseUrl.dict}`,
    });
  },

  getDictType(id) {
    return request({
      url: `/getOne/${id}`,
      method: "get",
      baseURL: `${baseUrl.dict}`,
    });
  },

  addDictType(data) {
    return request({
      url: `/type`,
      method: "post",
      baseURL: `${baseUrl.dict}`,
      data,
    });
  },

  addDictData(data) {
    return request({
      url: `/data`,
      method: "post",
      baseURL: `${baseUrl.dict}`,
      data,
    });
  },

  updateDictType(data) {
    return request({
      url: `/type`,
      method: "put",
      baseURL: `${baseUrl.dict}`,
      data,
    });
  },

  updateDictData(data) {
    return request({
      url: `/data`,
      method: "put",
      baseURL: `${baseUrl.dict}`,
      data,
    });
  },
};
